const http = require('http'),
      cheerio = require('cheerio'),
      log = console.log,
      fs = require('fs');

http.createServer((req,res)=>{
  let result = fs.readFileSync('./news.html');
  
  res.end(()=>{
    
    let $ = cheerio.load(result);
    $('.news-model>a').each(function(){

      let name = $(this).text();
      let time = $(this).next().text();

      if(time.indexOf('2018') !== -1 && req.url === '/'){

        let content = {
          'newsTitle':name,
          'createTime':time.slice(1,11)
        }

        log(JSON.stringify(content));
      }
    })

  })

}).listen(8080)
